package fr.cnam.projetSiw.client.structure.pages.suggest;

import java.util.ArrayList;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.cnam.projetSiw.client.ressources.GeneralBundle;
import fr.cnam.projetSiw.shared.Track;
import fr.cnam.projetSiw.widget.PhotoSquare;

public class RecordTrackViewImpl extends VerticalPanel implements RecordTrackView
{

	private Label lblTitleDeb = new Label("Top des chansons ");
	private Label lblTitleStrong = new Label(" enregistrées ");
	private Label lblTitleFin = new Label(" près de chez vous");
	FlowPanel flow = new FlowPanel();

	public RecordTrackViewImpl()
	{
		super();
		addStyleName(GeneralBundle.INSTANCE.css().tableSquare());
		lblTitleDeb.addStyleName(GeneralBundle.INSTANCE.css().titleSquare());
		lblTitleStrong.addStyleName(GeneralBundle.INSTANCE.css().titleSquare());
		lblTitleFin.addStyleName(GeneralBundle.INSTANCE.css().titleSquare());
		lblTitleStrong.addStyleName(GeneralBundle.INSTANCE.css().colorBlue());
		flow.addStyleName(GeneralBundle.INSTANCE.css().inline());
		flow.add(lblTitleDeb);
		flow.add(lblTitleStrong);
		flow.add(lblTitleFin);

		add(flow);
		this.setCellHeight(flow, "87px");
	}

	private Presenter presenter;

	@Override
	public void setPresenter(ZicPresenter presenter)
	{
		this.presenter = (Presenter) presenter;

	}

	@Override
	public void setData(ArrayList<Track> result)
	{
		this.clear();
		this.add(flow);
		if (result == null || result.isEmpty() || result.get(0) == null)
			add(new Label("Aucun résultats !")) ;
		int cpt = 0;
		for (Track track : result)
		{
			if (cpt == 6)
				break;
			if (track.getImgUrl() == null || track.getImgUrl().isEmpty())
				continue;
			PhotoSquare square = new PhotoSquare();
			
			String date = "Enregis. le " + DateTimeFormat.getFormat("dd MMMM yyyy").format(track.getRealiseDate());
			square.addSquareTrack(track.getImgUrl(), track.getArtist().getName(), date, track.getName());

			add(square);
			cpt++;
		}
	}

}
